<%-- 
  - Author: Abed Yaseen
  - Date: 02-Jan-2012
  - Copyright Notice: TRAKHEES
  - Description: form.jsp
 --%>
 <%@ include file="/WEB-INF/view/include.jsp"%>
 
    <div class="t_tmiddle-right">
    	<div id="tabs">
	      <ul id="TabHeader">
	        <li><a href="#MainDetails"><spring:message code="emp.visa.renewal.tab" /></a></li>
	        <li><a href="#Attachments"><spring:message code="header.attachments" /></a></li>
	           <li><a href="#Comments"><spring:message code="header.comments" /></a></li>
	      </ul>
	      <form:form modelAttribute="evRenewalModel" name="evRenewalModel"  id="evRenewalModel"  method="POST" enctype="multipart/form-data" class="t_form"
	      	>
			<spring:hasBindErrors
						name="evRenewalModel">
							<script type="text/javascript">
								$(document).ready(
										function() {
											jAlert('error', '<li><form:errors path="*" delimiter="<li>"/>',
													'<spring:message code="label.errormessage" />');
										});
					</script>
		    </spring:hasBindErrors>
		  
				<%@include file="MainTab.jsp" %>
	        	<%@include file="AttachmentsTab.jsp" %>
	        	<%@include file="CommentsTab.jsp" %>
	        	<div id="backgroundPopup"></div>
	        	<input type="hidden" name="strApplicationId" value="${ backOfficeAdminReview.strApplicationId}" / >
	        	<input type="hidden" name="strUserName" value="${backOfficeAdminReview.strUserName}" / >
	        	<input type="hidden" name="strTaskId" value="${backOfficeAdminReview.strTaskId}" / >
	        	<input type="hidden" name="strIncidentNo" value="${backOfficeAdminReview.strIncidentNo}" / >
	        	<input type="hidden" name="strStepName" value="${backOfficeAdminReview.strStepName}" / >
	        	<input type="hidden" name="processName" value="${backOfficeAdminReview.processName}" / >
	        	<input type="hidden" name="initiatedBy" value="${backOfficeAdminReview.initiatedBy}" />
	        	
		 </form:form>
	      
       </div>
    </div>
    <!--Middle Right Close-->
<script>

		var submAction = null;
		
		function setAction(inaction){
			submAction = inaction;
		}


        var $tabs ;
        
		//Validation - Required fields
		$().ready(function() {
		
			//CLOSING POPUP
			//Click the x event!
			$("#popupContactClose").click(function(){
				disablePopup();
			});
			//Click out event!
			$("#backgroundPopup").click(function(){
				disablePopup();
			});
			//Press Escape event!
			$(document).keypress(function(e){
				if(e.keyCode==27 && popupStatus==1){
					disablePopup();
				}
			});
			
			$(".topnav").accordion({
				accordion:false,
				speed: 500,
				closedSign: '<img src=\'resources/images/common/close.jpg\' />',
				openedSign: '<img src=\'resources/images/common/open.jpg\' />'
			});
	
			EmployeeAutoFiller.init("evrEmployeeId");
			EmployeeAutoFiller.defineFieldMapping("empNameEn",
			"empName");
			EmployeeAutoFiller.defineFieldMapping("empPostNo",
					"empPostNoMap");
			EmployeeAutoFiller.defineFieldMapping("empNationality",
					"empNationalityMap");
			EmployeeAutoFiller.defineFieldMapping("empCECNo",
					"empCECNoMap");
			EmployeeAutoFiller.fillFields();

			$tabs = $("#tabs").tabs();	
			$('#TabHeader').removeClass('ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all');
			$('#TabHeader > li').removeClass('ui-state-default ui-corner-top ui-state-active ui-state-hover');
			$('#tabs').removeClass('ui-widget ui-widget-content ui-corner-all');
			
			$('#tabs').tabs({
				select : function(event, ui) {
					
					var selected = $tabs.tabs('option', 'selected'); // => 0
					var clicked = ui.index; // => 0
										
					if( selected > clicked )
						return true;
					
					return true;
				}
			});
			
	
			$('#Main-Next').click(function() { // bind click event to link			
				$tabs.tabs('select', 1);
				return false;
			});
			
			$('#Comments-Next').click(function() { // bind click event to link			
				$tabs.tabs('select', 2);
				return false;
			});
			
			$('#Comments-Prev').click(function() { // bind click event to link			
				$tabs.tabs('select', 0);
				return false;
			});
			
			$('#Attachments-Prev').click(function() { // bind click event to link			
				$tabs.tabs('select', 1);
				return false;
			});
			
			$("#evRenewalModel").validate({

				onfocusout:false,
				onkeyup:false,
				onclick: false,			
				rules : {
					//Employee Details
					adminComments : {
						required : {
							depends: function(element) {
					           return submAction == "reject";
					        }
						}
					}				
				},
				
				submitHandler: function (form) {
					blockPage();
					form.submit();
				},
				
				showErrors : function(errorMap, errorList) {
					
					var errors = '<ul>';
					var label;				
					if (errorList.length) {
						$.each(errorMap, function(name, value) {
							label = $("label[for='" + name + "']").html();
							label = value + '[' + label + ']';
							errors = errors + '<li>' + label + '</li>';
							

						});
						errors = errors + '</ul>';
						jAlert('error', errors, '<spring:message code="label.errormessage" />');
						return false;
					}
				}		
			});
			
		});
		
		function cancelForm(divId){
			fancyConfirm('<spring:message code="message.cancel_confirmation_message" />'
					,'<spring:message code="button.No" />'
					,'<spring:message code="button.yes" />'
					, function(ret) {
						if(ret == true){
							//cancel
							var input = $("<input>").attr("type", "hidden").attr("name", "MainUserCancel").val("MainUserCancel");
							$('#evRenewalModel').append($(input));
							$('#evRenewalModel').submit();
							$.fancybox.showLoading();
						}
			});
		}
</script>